package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ASM_fASEDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;
	
	
	public ASM_fASEDS(Context context) {
		this.context = context;
		dbHelper  = new ASM_DB(context);
		
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_fASE det) 
	{
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen())
		{
			open();
		}
		
		
		ContentValues values = new ContentValues();
		values.put(ASM_DB.asmFAse_ASECode, det.getAsmFAse_ASECode());
		values.put(ASM_DB.asmFAse_ASEName, det.getAsmFAse_ASEName());
		values.put(ASM_DB.asmFAse_ASMCode,det.getAsmFAse_ASMCode());
		


		
		count = (int) dB.insert(ASM_DB.ASM_FASE, null, values);

		dB.close();
		return count;
		
	}
	
	public String getasename(String ASMCode) 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
	
		String ASEName = null;
		String selectQuery = "select ASEName from fASE where ASMCode = '"+ASMCode+"'";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
		
			ASEName = cursor.getString(0);
		
		}
		
		return ASEName;
	}
	public ArrayList<String> getasename1(String ASMCode) 
	{
		if (dB == null) 
		{
			open();
		} else if (!dB.isOpen()) 
		{
			open();
		}
		ArrayList<String> ASEName = new ArrayList<String>();
		
	
		String selectQuery = "select ASMName from fASM where ASMCode = '"+ASMCode+"'";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{

			String ASEName1 = cursor.getString(0);
		
		
			ASEName.add(ASEName1);

			
		}
		
		return ASEName;
	}
}
